package org.mspring.mlog.web.module.admin;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mspring.platform.config.ConfigService;
import org.mspring.platform.security.exception.UNLoginException;
import org.mspring.platform.web.freemarker.widget.stereotype.Widget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 *
 * @since 2014年4月15日
 * @author Administrator
 */
@Widget
@RequestMapping("/admin/config")
public class Admin_ConfigWidget extends Admin_AbstractWidget {
    @Autowired
    private ConfigService configService;

    @RequestMapping("/system")
    public String system(@RequestParam Map<String, String> configs, HttpServletRequest request, HttpServletResponse response, Model model) {
        configs = configService.getConfigs();
        model.addAllAttributes(configs);
        return "/admin/config/system";
    }

    @RequestMapping("/system/save")
    public String system_save(@RequestParam Map<String, String> configs, HttpServletRequest request, HttpServletResponse response, Model model) throws UNLoginException {
        configService.setConfigs(configs);
        return prompt(model, "配置保存成功", "/admin/config/system");
    }

    @RequestMapping("/seo")
    public String seo(@RequestParam Map<String, String> configs, HttpServletRequest request, HttpServletResponse response, Model model) {
        configs = configService.getConfigs();
        model.addAllAttributes(configs);
        return "/admin/config/seo";
    }

    @RequestMapping("/seo/save")
    public String seo_save(@RequestParam Map<String, String> configs, HttpServletRequest request, HttpServletResponse response, Model model) throws UNLoginException {
        configService.setConfigs(configs);
        return prompt(model, "配置保存成功", "/admin/config/seo");
    }
}
